<?php
/**
* @version              $Id: view.html.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package              Joomla
* @subpackage   Poll
* @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license              GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');

class amapViewliste_adherents_nb_contrats extends JView {

var $amap;

        function display($tpl = null)
        {
   $mainframe =& JFactory::getApplication();

                $database =& JFactory::getDBO();
                $document =& JFactory::getDocument();
                $user =& JFactory::getUser();


$ida=$mainframe->getUserState('amap_ida');

$html='<html>';
$html.='<div style="text-align:left;"><strong>Liste du nombre de contrats validés et saisis par adherent ayant demandé l\'adhésion à la période Décembre 2014 au '.date('d/m/Y').'</strong></div>(Récapitulation en bas du tableau)';



//$sql="SELECT amap_adherent.Nom as nom, amap_adherent.Prenom as prenom, amap_adherent.Email as email, (SELECT  COUNT(amap_abonnementadherent.NomAbonnement) FROM amap_abonnementadherent WHERE amap_abonnementadherent.Statut='Abonne' AND amap_abonnementadherent.IDA=amap_adherent.IDA )  as Abonne,(SELECT  COUNT(amap_abonnementadherent.NomAbonnement) FROM amap_abonnementadherent WHERE  amap_abonnementadherent.IDA=amap_adherent.IDA ) as Saisis FROM amap_adherent LEFT JOIN amap_abonnementadherent ON amap_adherent.IDA=amap_abonnementadherent.IDA GROUP BY amap_adherent.IDA ORDER BY amap_adherent.Nom, amap_adherent.Prenom";
$sql="SELECT amap_adherent.Nom as nom, amap_adherent.Prenom as prenom, amap_adherent.Email as email, (SELECT  COUNT(amap_abonnementadherent.NomAbonnement) FROM amap_abonnementadherent WHERE amap_abonnementadherent.Statut='Abonne' AND amap_abonnementadherent.IDA=amap_adherent.IDA )  as Abonne,(SELECT  COUNT(amap_abonnementadherent.NomAbonnement) FROM amap_abonnementadherent WHERE  amap_abonnementadherent.IDA=amap_adherent.IDA ) as Saisis FROM amap_adherent LEFT JOIN amap_abonnementadherent ON amap_adherent.IDA=amap_abonnementadherent.IDA JOIN amap_adhesion ON amap_adherent.IDA=amap_adhesion.IDA GROUP BY amap_adherent.IDA ORDER BY amap_adherent.Nom, amap_adherent.Prenom";

//$sql="SELECT amap_adherent.Nom as nom, amap_adherent.Prenom as prenom, amap_adherent.Email as email, amap_adherent.IDJ as IDJ,

//(SELECT  COUNT(amap_abonnementadherent.NomAbonnement) FROM amap_abonnementadherent WHERE amap_abonnementadherent.Statut='Abonne' AND amap_abonnementadherent.IDA=amap_adherent.IDA )  as Abonne,
//(SELECT  COUNT(amap_abonnementadherent.NomAbonnement) FROM amap_abonnementadherent WHERE  amap_abonnementadherent.IDA=amap_adherent.IDA ) as Saisis
//FROM amap_adherent
//RIGHT JOIN xigdx_users ON xigdx_users.id=amap_adherent.IDJ
//LEFT JOIN amap_abonnementadherent ON amap_adherent.IDA=amap_abonnementadherent.IDA GROUP BY amap_adherent.IDA
//ORDER BY amap_adherent.Nom, amap_adherent.Prenom
//";


$database->setQuery( $sql);
$liste=$database->loadRowList();
//print_r($liste);

$html.="<TABLE border='1'><TR><TD>Nom</TD><TD>Prénom</TD><TD>email</TD><TD>Nombre de contrats validés</TD><TD>Nombre de contrats saisis</TD></TR>";
$nb=$passaisi=0;
foreach ($liste as $adherent)
{
$nb=$nb+1;
if($adherent['4']== 0 OR $adherent['4']==NULL ) $passaisi=$passaisi+1;
$html.='<TR><TD>';
//      print_r($adherent);
//20140919BM
if ($adherent['4']==0) $adherent['4']="";
if ($adherent['3']==0) $adherent['3']="";

        $html.= $adherent['0'].'</TD><TD>'.$adherent['1'].'</TD><TD>'.$adherent['2'].'</TD><TD align="center">'.$adherent['3'].'</TD><TD align="center">'.$adherent['4'].'</TD>';

$html.='<TR>';
}
$html.="</TABLE>";

$html.= '<br> Nombre total d\'adherents (c\'est à dire ont rempli la fiche adhérent de l\'AMAP <strong>ET</strong> ont demandé l\'adhésion à la période Décembre 2014): <strong>'. $nb.'</strong><br>Dont nombre d\'adhérents (définition=idem ci dessus) qui ont saisi des contrats :<strong>'.($nb-$passaisi).'</strong>'; 
echo $html;
//contratPDF($html,$nom_contrat);
}
}
?>
